/*******************************************************************************
File: 8_cpfp_other_involvement
Project: CPKIN
Purpose: This .do file cleans and analyzes CPFP data on involvement of other actors in child protection activities 
Author: Akshay Dixit
Date Created: March 7, 2019
Date modified: July 2, 2020
********************************************************************************/

clear all
set more off

***THIS IS THE INPUT THAT MUST BE CHANGED SPECIFIC TO THE USER***
*gl identity ""
*gl user "" 

********************************************************************************

***Creating Global File Paths***'
gl data "$user/data"
gl dof "$user/do files"
gl analysis "$user/analysis"

********************************************************************************

u "$data/endline_fp_data.dta", clear

* Stratification variable - Chiefdom
gl chiefdom = "bagruwa_chief barri_chief bumpeh_chief fakunya_chief gallinas_perri_chief kaiyamba_chief kamarjei_chief kori_chief kowa_chief kpaka_chief malin_chief sowa_chief"

* Control variables
gl controls = "wealth_index female age attend_school fp_visit vil_pop"

count if focal_status == .	//No missing values
forvalues i=1/3 {
	g focal_status_`i' = (focal_status == `i')
}	

		/*
		An additional control needed is focal person status: currently active, replaced, previous FP.			
		*/

********************************************************************************

* Outcome variables

	//Family, Parents, Older Children
local family fam_med fam_study fam_needs fam_preg fam_sch fam_pnsh_hvywork fam_sev_beat fam_care ///
oldchd_med oldchd_study oldchd_needs oldchd_preg oldchd_sch oldchd_pnsh_hvywork oldchd_sev_beat oldchd_care ///
par_med par_study par_needs par_preg par_sch par_pnsh_hvywork par_sev_beat par_care 

foreach var of local family {
	replace `var' = 0 if (`var' == 4)	//Changing 4 (This problem hasn't happened in the past six months) to 0 for ease of coding
	replace `var' = 0 if (`var' == .d)	//.d is the same as 4 (This problem hasn't happened)
	replace `var' = 0 if (`var' == .c)	//.c means the respondent is unaware of the existence of this stakeholder
}	
	
egen response_family = rowtotal(fam_med fam_study fam_needs fam_preg fam_sch fam_pnsh_hvywork fam_sev_beat fam_care ///
oldchd_med oldchd_study oldchd_needs oldchd_preg oldchd_sch oldchd_pnsh_hvywork oldchd_sev_beat oldchd_care ///
par_med par_study par_needs par_preg par_sch par_pnsh_hvywork par_sev_beat par_care), missing

replace response_family = 1 if (response_family > 0 & response_family != .)

********************************************************************************
	
	//Community - Village elite, children's clubs, community members, Child Welfare Committee (CWC), religious groups, women's clubs 
local community bus_rich_med bus_rich_study bus_rich_needs bus_rich_preg bus_rich_sch bus_rich_pnsh_hvywork bus_rich_sev_beat bus_rich_care ///
chdclubs_med chdclubs_study chdclubs_needs chdclubs_preg chdclubs_sch chdclubs_pnsh_hvywork chdclubs_sev_beat chdclubs_care ///
com_med com_study com_needs com_preg com_sch com_pnsh_hvywork com_sev_beat com_care ///
cwc_med cwc_study cwc_needs cwc_preg cwc_sch cwc_pnsh_hvywork cwc_sev_beat cwc_care ///
religious_med religious_study religious_needs religious_preg religious_sch religious_pnsh_hvywork religious_sev_beat religious_care ///
wmensclubs_med wmensclubs_study wmensclubs_needs wmensclubs_preg wmensclubs_sch wmensclubs_pnsh_hvywork wmensclubs_sev_beat wmensclubs_care

foreach var of local community {
	replace `var' = 0 if (`var' == 4) 
	replace `var' = 0 if (`var' == .d) 
	replace `var' = 0 if (`var' == .c)
}

egen response_community = rowtotal(bus_rich_med bus_rich_study bus_rich_needs bus_rich_preg bus_rich_sch bus_rich_pnsh_hvywork bus_rich_sev_beat bus_rich_care ///
chdclubs_med chdclubs_study chdclubs_needs chdclubs_preg chdclubs_sch chdclubs_pnsh_hvywork chdclubs_sev_beat chdclubs_care ///
com_med com_study com_needs com_preg com_sch com_pnsh_hvywork com_sev_beat com_care ///
cwc_med cwc_study cwc_needs cwc_preg cwc_sch cwc_pnsh_hvywork cwc_sev_beat cwc_care ///
religious_med religious_study religious_needs religious_preg religious_sch religious_pnsh_hvywork religious_sev_beat religious_care ///
wmensclubs_med wmensclubs_study wmensclubs_needs wmensclubs_preg wmensclubs_sch wmensclubs_pnsh_hvywork wmensclubs_sev_beat wmensclubs_care), missing

replace response_community = 1 if (response_community > 0 & response_community != .)

********************************************************************************
	
	//Government - Local councilor, Family Support Unit (FSU), Social Development Offidcers (SDOs), Government Social Workers
local government councilor_med councilor_study councilor_needs councilor_preg councilor_sch councilor_pnsh_hvywork councilor_sev_beat councilor_care ///
fsu_med fsu_study fsu_needs fsu_preg fsu_sch fsu_pnsh_hvywork fsu_sev_beat fsu_care ///
sdo_med sdo_study sdo_needs sdo_preg sdo_sch sdo_pnsh_hvywork sdo_sev_beat sdo_care ///
sworker_med sworker_study sworker_needs sworker_preg sworker_sch sworker_pnsh sworker_sev_beat sworker_care

foreach var of local government {
	replace `var' = 0 if (`var' == 4) 
	replace `var' = 0 if (`var' == .d) 
	replace `var' = 0 if (`var' == .c)	
}

egen response_govt = rowtotal(councilor_med councilor_study councilor_needs councilor_preg councilor_sch councilor_pnsh_hvywork councilor_sev_beat councilor_care ///
fsu_med fsu_study fsu_needs fsu_preg fsu_sch fsu_pnsh_hvywork fsu_sev_beat fsu_care ///
sdo_med sdo_study sdo_needs sdo_preg sdo_sch sdo_pnsh_hvywork sdo_sev_beat sdo_care ///
sworker_med sworker_study sworker_needs sworker_preg sworker_sch sworker_pnsh sworker_sev_beat sworker_care), missing

replace response_govt = 1 if (response_govt > 0 & response_govt != .)

********************************************************************************

	//Chiefs - Paramount chiefs, village chiefs, Section chiefs
local chiefs pc_med pc_study pc_needs pc_preg pc_sch pc_pnsh_hvywork pc_sev_beat pc_care ///
secchief_med secchief_study secchief_needs secchief_preg secchief_sch secchief_pnsh_hvywork secchief_sev_beat secchief_care ///
vilchief_med vilchief_study vilchief_needs vilchief_preg vilchief_sch vilchief_pnsh_hvywork vilchief_sev_beat vilchief_care

foreach var of local chiefs {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}

egen response_chiefs = rowtotal(pc_med pc_study pc_needs pc_preg pc_sch pc_pnsh_hvywork pc_sev_beat pc_care ///
secchief_med secchief_study secchief_needs secchief_preg secchief_sch secchief_pnsh_hvywork secchief_sev_beat secchief_care ///
vilchief_med vilchief_study vilchief_needs vilchief_preg vilchief_sch vilchief_pnsh_hvywork vilchief_sev_beat vilchief_care), missing

replace response_chiefs = 1 if (response_chiefs > 0 & response_chiefs != .)

********************************************************************************
	
	//Teachers and SMC members
local edu smc_med smc_study smc_needs smc_preg smc_sch smc_pnsh_hvywork smc_sev_beat smc_care ///
tchr_med tchr_study tchr_needs tchr_preg tchr_sch tchr_pnsh_hvywork tchr_sev_beat tchr_care

foreach var of local edu {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}

egen response_edu = rowtotal(smc_med smc_study smc_needs smc_preg smc_sch smc_pnsh_hvywork smc_sev_beat smc_care ///
tchr_med tchr_study tchr_needs tchr_preg tchr_sch tchr_pnsh_hvywork tchr_sev_beat tchr_care), missing

replace response_edu = 1 if (response_edu > 0 & response_edu != .)

********************************************************************************
	
	//Community Health Officers
local cho cho_med cho_study cho_needs cho_preg cho_sch cho_pnsh_hvywork cho_sev_beat cho_care

foreach var of local cho {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}	

egen response_cho = rowtotal(cho_med cho_study cho_needs cho_preg cho_sch cho_pnsh_hvywork cho_sev_beat cho_care), missing

replace response_cho = 1 if (response_cho > 0 & response_cho != .)
	
********************************************************************************
	
	//NGOs
local ngos actionaid_med actionaid_study actionaid_needs actionaid_preg actionaid_sch actionaid_pnsh_hvywork actionaid_sev_beat actionaid_care ///
chdfund_med chdfund_study chdfund_needs chdfund_preg chdfund_sch chdfund_pnsh_hvywork chdfund_sev_beat chdfund_care ///
ngos_med ngos_study ngos_needs ngos_preg ngos_sch ngos_pnsh_hvywork ngos_sev_beat ngos_care ///
plan_med plan_study plan_needs plan_preg plan_sch plan_pnsh_hvywork plan_sev_beat plan_care ///
savechdrn_med savechdrn_study savechdrn_needs savechdrn_preg savechdrn_sch savechdrn_pnsh_hvywork savechdrn_sev_beat savechdrn_care ///
unicef_med unicef_study unicef_needs unicef_preg unicef_sch unicef_pnsh_hvywork unicef_sev_beat unicef_care ///
wrldvision_med wrldvision_study wrldvision_needs wrldvision_preg wrldvision_sch wrldvision_pnsh_hvywork wrldvision_sev_beat wrldvision_care

foreach var of local ngos {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}	

egen response_ngos = rowtotal(actionaid_med actionaid_study actionaid_needs actionaid_preg actionaid_sch actionaid_pnsh_hvywork actionaid_sev_beat actionaid_care ///
chdfund_med chdfund_study chdfund_needs chdfund_preg chdfund_sch chdfund_pnsh_hvywork chdfund_sev_beat chdfund_care ///
ngos_med ngos_study ngos_needs ngos_preg ngos_sch ngos_pnsh_hvywork ngos_sev_beat ngos_care ///
plan_med plan_study plan_needs plan_preg plan_sch plan_pnsh_hvywork plan_sev_beat plan_care ///
savechdrn_med savechdrn_study savechdrn_needs savechdrn_preg savechdrn_sch savechdrn_pnsh_hvywork savechdrn_sev_beat savechdrn_care ///
unicef_med unicef_study unicef_needs unicef_preg unicef_sch unicef_pnsh_hvywork unicef_sev_beat unicef_care ///
wrldvision_med wrldvision_study wrldvision_needs wrldvision_preg wrldvision_sch wrldvision_pnsh_hvywork wrldvision_sev_beat wrldvision_care), missing

replace response_ngos = 1 if (response_ngos > 0 & response_ngos != .)

********************************************************************************
		
* Label variables
lab var response_community "Community"
lab var response_govt "Government"
lab var response_chiefs "Chiefs"
lab var response_edu "Teachers and SMC members"
lab var response_cho "Community Health Officers"
lab var response_ngos "NGOs"

lab var treatment "Treatment"
lab var wealth_index "Wealth index" 
lab var female "Female"
lab var age "Age"
lab var attend_school "Ever attended school" 
lab var fp_visit "Village visited by UNICEF monitoring team"
lab var vil_pop "Village population"
lab var chief "Respondent: Chief"
lab var sms_received "CPKIN SMS received"
lab var focal_status_1 "FP status: Current active, never replaced"
lab var focal_status_2 "FP status: Current active, replaced prior FP in past year"
lab var focal_status_3 "FP status: Previous FP, replaced in past year" 

********************************************************************************

*** Export ITT estimates to Excel for making bar graphs ***

cd "$analysis"

putexcel set "cpfp_plots.xlsx", sheet(other_involvement) modify

putexcel A1=("Group") B1=("Community") C1=("Government") D1=("Chiefs") 
putexcel E1=("Teachers & SMC members") F1=("Community Health Officers") G1=("NGOs")
putexcel H1=("1.96se1") I1=("1.96se2") J1=("1.96se3") K1=("1.96se4") L1=("1.96se5") M1=("1.96se6") 
putexcel A2=("Control") A3=("Treatment") 

reg response_community treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_community if treatment == 0
putexcel B2 = (r(mean))
putexcel B3 = ((_b[treatment]) + (r(mean)))
putexcel H3 = (1.96*(_se[treatment]))

reg response_govt treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_govt if treatment == 0
putexcel C2 = (r(mean))
putexcel C3 = ((_b[treatment]) + (r(mean)))
putexcel I3 = (1.96*(_se[treatment]))

reg response_chiefs treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_chiefs if treatment == 0
putexcel D2 = (r(mean))
putexcel D3 = ((_b[treatment]) + (r(mean)))
putexcel J3 = (1.96*(_se[treatment]))

reg response_edu treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_edu if treatment == 0
putexcel E2 = (r(mean))
putexcel E3 = ((_b[treatment]) + (r(mean)))
putexcel K3 = (1.96*(_se[treatment]))

reg response_cho treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_cho if treatment == 0
putexcel F2 = (r(mean))
putexcel F3 = ((_b[treatment]) + (r(mean)))
putexcel L3 = (1.96*(_se[treatment]))

reg response_ngos treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum response_ngos if treatment == 0
putexcel G2 = (r(mean))
putexcel G3 = ((_b[treatment]) + (r(mean)))
putexcel M3 = (1.96*(_se[treatment]))

********************************************************************************  

clear

